package java8;

import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author lzy
 * Create DateTime: 2018/7/18 15:39
 * @version v1.0
 */
public class TestLambda3 {

    @Test
    public void test1() {
        List<Employee> employees = Arrays.asList(
                new Employee("张三", 18, 9999.99),
                new Employee("李四", 38, 5555.555),
                new Employee("王五", 50, 6666.66),
                new Employee("赵柳", 16, 3333.33),
                new Employee("田七", 8, 7777.77));

        Collections.sort(employees, (e1, e2) -> {
            if (e1.getAge() == e2.getAge()) {
                return e1.getName().compareTo(e2.getName());
            } else {
                return Integer.compare(e1.getAge(), e2.getAge());
            }
        });

        employees.forEach(System.out::println);
    }

    @Test
    public void test2() {
        String trimStr = strHandler("\t\t\t 测试字符串 ", s -> s.trim());
        System.out.println(trimStr);

        String upper = strHandler("abdfaddf", s -> s.toUpperCase());
        System.out.println(upper);
    }

    @Test
    public void test3() {
        op(12L, 34L, (x, y) -> x + y);

        op(34L, 343L, (x, y) -> x * y);
    }

    // 需求：用于处理字符串
    public String strHandler(String str, MyFounction myFounction) {
        return myFounction.getValue(str);
    }

    // 需求:对于两个Long型数组进行处理
    public void op(Long l1, Long l2, MyFunction2<Long, Long> fun) {
        System.out.println(fun.getValue(l1, l2));
    }
}
